package work.lianwei;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Gong.Yang
 */
public class JsonTest {
    public static void main(String[] args) {
        String json = FileUtil.readString(filePath, Charset.defaultCharset());

        JSONArray objects = JSONUtil.parseArray(json);
        List<ProvinceCityArea> areas = new ArrayList<>();
        for (int i = 0; i < objects.size(); i++) {
            JSONObject jsonObject = objects.getJSONObject(i);
            areas.add(new ProvinceCityArea(jsonObject.getStr("code"),jsonObject.getStr("name")));
        }

        areas.stream().collect(Collectors.toMap(ProvinceCityArea::getCode, ProvinceCityArea::getName));


    }
    @Data
    @AllArgsConstructor
    static class ProvinceCityArea{
        private String code;
        private String name;
    }

    private static final String filePath = "E:\\work-records\\Apple\\bio生产省市获取问题\\test.json";

}
